package com.zihao.blog.handle;

import com.zihao.blog.enums.ResultCodeEnum;
import com.zihao.blog.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalDefaultExceptionHandler {
    /**
     * 处理参数异常，一般用于校验body参数
     *
     * @param e
     * @return
     */
    @ExceptionHandler(MethodArgumentNotValidException.class)
    @ResponseBody
    public Result handleValidationBodyException(MethodArgumentNotValidException e) {
        log.error("异常类 HttpMessageNotReadableException {},", e.getMessage());
        return Result.error(ResultCodeEnum.PARAM_ERROR);
    }

}